package pl.register.android.util.time;

import android.text.format.DateFormat;

import java.util.Calendar;
import java.util.Date;

/**
 * User: Mateusz Strzelecki
 * Date: 25.10.12
 */
public class DateUtil {

    public static Date resetTime(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTime();
    }

    public static Date today() {
        return resetTime(new Date());
    }

    public static String getDateInFormat(String format, Date date, String defaultString) {
        if (date != null) {
            return DateFormat.format(format, date).toString();
        } else {
            return defaultString;
        }
    }
}
